package cn.cinz.controller;


import cn.cinz.pojo.Blog;
import cn.cinz.service.BlogService;
import cn.cinz.util.IdUtils;
import com.alibaba.fastjson.JSON;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.*;


/**
 * 博客视图跳转
 */

@CrossOrigin
@Controller
@RequestMapping("/user")
public class BlogController {

    @Autowired
    @Qualifier("BlogServiceImpl")
    BlogService blogService;


    //插入博客
    @RequestMapping("/addBlog")
    public String addDiary(@Param("blogTitle") String blogTitle, @Param("blogMemo") String blogMemo, @Param("blogStatus") String blogStatus, @Param("blogValue") String blogValue, HttpSession session) {
        String blogId = IdUtils.getId();//生成博客id
        Blog diary = new Blog(blogId, blogTitle, new Date(System.currentTimeMillis()), blogMemo, blogValue, blogStatus, String.valueOf(session.getAttribute("userName")));

        int i = blogService.addBlog(diary);//插入数据

        return "redirect:/user/blog.html";
    }

}
